<?php
include($gDOCUMENT_ROOT_SYSTEM.'/include/dbconnect.php');









function getWrittenLanguageTagAndOriginalName()
{
	global $dbh;
	$sql_1 = "SELECT `id`,`tag` FROM `written_language`";
	$id_name = array();
	$result_1 = $dbh->query($sql_1);
	$result_1->setFetchMode(PDO::FETCH_ASSOC);
	$id_tag = $result_1->fetchAll();
	$sql_2 = "SELECT * FROM `written_language_name_translation`";
	$result_2 = $dbh->query($sql_2);
	$result_2->setFetchMode(PDO::FETCH_ASSOC);
	$id_name = $result_2->fetchAll();
	foreach($id_tag as $one_id_tag)
	{
		foreach($id_name as $one_id_name)
		{
			if($one_id_name['written_language_id']==$one_id_tag['id'])
			{
				$tag_name[$one_id_tag['tag']] = $one_id_name[$one_id_tag['tag']];
			}
		}
    }
    return $tag_name;
}

function getSpokenLanguageTagAndName($first_tag='zh-Hans-CN')
{
	global $dbh;
	$sql_1 = "SELECT `id`,`tag` FROM `spoken_language`";
	$id_name = array();
	$result_1 = $dbh->query($sql_1);
	$result_1->setFetchMode(PDO::FETCH_ASSOC);
	$id_tag = $result_1->fetchAll();
	$sql_2 = "SELECT `spoken_language_id`,`".$first_tag."` FROM `spoken_language_name_translation`";
	$result_2 = $dbh->query($sql_2);
	$result_2->setFetchMode(PDO::FETCH_ASSOC);
	$id_name = $result_2->fetchAll();
	foreach($id_tag as $one_id_tag)
	{
		foreach($id_name as $one_id_name)
		{
			if($one_id_name['spoken_language_id']==$one_id_tag['id'])
			{
				$tag_name[$one_id_tag['tag']] = $one_id_name[$first_tag].'['.$one_id_tag['tag'].']';
			}
		}
    }
    return $tag_name;
}

?>